package com.dopies.ecmobile.activity;


import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.dopies.BeeFramework.activity.BaseActivity;
import com.dopies.BeeFramework.model.BusinessResponse;
import com.dopies.ecmobile.R;
import com.dopies.ecmobile.model.GoodDetailModel;
import com.dopies.ecmobile.model.ProtocolConst;
import com.external.androidquery.callback.AjaxStatus;

public class GoodsDescActivity extends BaseActivity implements BusinessResponse {

	
	private TextView title;
	private ImageView back;
	private GoodDetailModel goodsModel;
	private WebView webView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.helpweb);
		
		Intent intent = getIntent();
		int id = intent.getIntExtra("id", 0);
		
		title = (TextView) findViewById(R.id.top_view_text);
        Resources resource = getBaseContext().getResources();
        String  det=resource.getString(R.string.gooddetail_product);
		title.setText(det);
		
		back = (ImageView) findViewById(R.id.top_view_back);
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		webView = (WebView) findViewById(R.id.help_web);
		
		goodsModel = new GoodDetailModel(this);
		goodsModel.addResponseListener(this);
		goodsModel.goodsDesc(id);
		
		webView.setWebViewClient(new WebViewClient() { // 通过webView打开链接，不调用系统浏览器

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// TODO Auto-generated method stub
				view.loadUrl(url);
				return true;
			}
		});
		
		webView.setInitialScale(25);
		WebSettings webSettings = webView.getSettings();  
		webSettings.setJavaScriptEnabled(true); 
		webSettings.setBuiltInZoomControls(true);
		webSettings.setSupportZoom(true);
		
		webView.getSettings().setUseWideViewPort(true);
		webView.getSettings().setLoadWithOverviewMode(true);
		
	} 

	@Override
	public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status)
			throws JSONException {
		// TODO Auto-generated method stub
		
		if(url.endsWith(ProtocolConst.GOODSDESC)) {
			
			webView.loadDataWithBaseURL(null,goodsModel.goodsWeb,"text/html","utf-8",null);
			
		}
		
	}
	
}
